package springjdbc;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Component;

import domain.Users;

@Component
public class UserDaoParmeter extends NamedParameterJdbcDaoSupport{
	
	@Autowired
	public void setJT(JdbcTemplate jdbcTemplate) {
		super.setJdbcTemplate(jdbcTemplate);
	}
	
	@Test
	public void test() {
		NamedParameterJdbcTemplate template = this.getNamedParameterJdbcTemplate();
		
		String sql="insert into user(USERID,USERNAME,PASSWORD,group_id) value(:USERID,:USERNAME,:PASSWORD,:group_id)";
		
		Users users = new Users();
		
		users.setUSERID(123);
		users.setUSERNAME("kkk");
		users.setPASSWORD("sdasdasd");
		users.setGroup_id(2);
		
		SqlParameterSource paramSource=new BeanPropertySqlParameterSource(users);
		template.update(sql, paramSource);
	}

}
